/*-
 * PID.java          TP-Protocol-Identifier (TP-PID)
 *
 * $LastChangedBy: stein $
 * $LastChangedRevision: 95 $
 * $LastChangedDate: 2007-02-13 16:19:24 +0000 (Tue, 13 Feb 2007) $
 * $HeadURL: svn://localhost/SMS/src/com/googlecode/attention/sms/pdu/PID.java $
 *
 * Copyright (c) 2007, Stein Gunnar Bakkeby
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.attention.sms.pdu;

import com.googlecode.attention.util.IntValue;

import static com.googlecode.attention.util.bit.ByteBitValues.*;

/**
 * TP-Protocol-Identifier (TP-PID).
 * <BR>
 * The TP-Protocol-Identifier consists of one octet, and the bits in the
 * octet are used as follows:
 * <BR>
 * <BR>The MS shall interpret reserved, obsolete, or unsupported values as
 * the value 00000000 but shall store them exactly as received.
 * <BR>
 * <BR>The SC may reject messages with a TP-Protocol-Identifier
 * containing a reserved value or one which is not supported.
 * <BR>
 * <TABLE>
 * <TR><TD>bit7</TD><TD>bit6</TD><TD>usage</TD></TR>
 * <TR><TD>0</TD><TD>0</TD><TD>Assigns bits 0..5 as defined below</TD></TR>
 * <TR><TD>0</TD><TD>1</TD><TD>Assigns bits 0..5 as defined below</TD></TR>
 * <TR><TD>1</TD><TD>0</TD><TD>reserved</TD></TR>
 * <TR><TD>1</TD><TD>1</TD><TD>Assigns bits 0-5 for SC specific use</TD></TR>
 * </TABLE>
 * <BR>
 * <BR>In the case where bit 7 = 0 and bit 6 = 0,
 * <BR>
 * <BR>bit 5 indicates telematic interworking:
 * <BR>value = 0 : no interworking, but SME-to-SME protocol
 * <BR>value = 1 : telematic interworking
 * <BR>
 * <BR>In the case of telematic interworking, the following five bit
 * patterns in bits 4..0 are used to indicate different types of
 * telematic devices:
 * <BR>
 * <TABLE>
 * <TR><TD>4.. .0</TD><TD></TD></TR>
 * <TR><TD>00000</TD><TD>implicit - device type is specific to this SC, or can be concluded on the basis of the address</TD></TR>
 * <TR><TD>00001</TD><TD>telex (or teletex reduced to telex format)</TD></TR>
 * <TR><TD>00010</TD><TD>group 3 telefax</TD></TR>
 * <TR><TD>00011</TD><TD>group 4 telefax</TD></TR>
 * <TR><TD>00100</TD><TD>voice telephone (i.e. conversion to speech)</TD></TR>
 * <TR><TD>00101</TD><TD>ERMES (European Radio Messaging System)</TD></TR>
 * <TR><TD>00110</TD><TD>National Paging system (known to the SC)</TD></TR>
 * <TR><TD>00111</TD><TD>Videotex (T.100 [20] /T.101 [21])</TD></TR>
 * <TR><TD>01000</TD><TD>teletex, carrier unspecified</TD></TR>
 * <TR><TD>01001</TD><TD>teletex, in PSPDN</TD></TR>
 * <TR><TD>01010</TD><TD>teletex, in CSPDN</TD></TR>
 * <TR><TD>01011</TD><TD>teletex, in analog PSTN</TD></TR>
 * <TR><TD>01100</TD><TD>teletex, in digital ISDN</TD></TR>
 * <TR><TD>01101</TD><TD>UCI (Universal Computer Interface, ETSI DE/PS 3 01-3)</TD></TR>
 * <TR><TD>01110..01111</TD><TD>(reserved, 2 combinations)</TD></TR>
 * <TR><TD>10000</TD><TD>a message handling facility (known to the SC)</TD></TR>
 * <TR><TD>10001</TD><TD>any public X.400-based message handling system</TD></TR>
 * <TR><TD>10010</TD><TD>Internet Electronic Mail</TD></TR>
 * <TR><TD>10011..10111</TD><TD>(reserved, 5 combinations)</TD></TR>
 * <TR><TD>11000..11110</TD><TD>values specific to each SC, usage based on mutual agreement between the SME and the SC (7 combinations available for each SC)</TD></TR>
 * <TR><TD>11111</TD><TD>A GSM/UMTS mobile station. The SC converts the SM from the received. TP-Data-Coding-Scheme to any data coding scheme supported by that MS (e.g. the default).</TD></TR>
 * </TABLE>
 * <BR>
 * <BR>If bit 5 has value 1 in an SMS-SUBMIT PDU, it indicates that the
 * SME is a telematic device of a type which is  indicated in bits 4..0,
 * and requests the SC to convert the SM into a form suited for that
 * device type. If the destination network is ISDN, the SC must also select
 * the proper service indicators for connecting to a device of that type.
 * <BR>
 * <BR>If bit 5 has value 1 in an SMS-DELIVER PDU, it indicates that the
 * SME is a telematic device of a type which is indicated in bits 4..0.
 * <BR>
 * <BR>If bit 5 has value 0 in an SMS-DELIVER PDU, the value in bits 4..0
 * identifies the SM-AL protocol being used between the SME and the MS.
 * <BR>
 * <BR>Note that for the straightforward case of simple MS-to-SC short
 * message transfer the Protocol Identifier is set to the value 0. In the
 * case where bit 7 = 0, bit 6 = 1, bits 5..0 are used as defined below
 * <BR>
 * <TABLE>
 * <TR><TD>5 .. . .0</TD><TD></TD></TR>
 * <TR><TD>000000</TD><TD>Short Message Type 0</TD></TR>
 * <TR><TD>000001</TD><TD>Replace Short Message Type 1</TD></TR>
 * <TR><TD>000010</TD><TD>Replace Short Message Type 2</TD></TR>
 * <TR><TD>000011</TD><TD>Replace Short Message Type 3</TD></TR>
 * <TR><TD>000100</TD><TD>Replace Short Message Type 4</TD></TR>
 * <TR><TD>000101</TD><TD>Replace Short Message Type 5</TD></TR>
 * <TR><TD>000110</TD><TD>Replace Short Message Type 6</TD></TR>
 * <TR><TD>000111</TD><TD>Replace Short Message Type 7</TD></TR>
 * <TR><TD>001000..011101</TD><TD>Reserved</TD></TR>
 * <TR><TD>011110</TD><TD>Enhanced Message Service (Obsolete)</TD></TR>
 * <TR><TD>011111</TD><TD>Return Call Message</TD></TR>
 * <TR><TD>100000..111011</TD><TD>Reserved</TD></TR>
 * <TR><TD>111100</TD><TD>ANSI-136 R-DATA</TD></TR>
 * <TR><TD>111101</TD><TD>ME Data download</TD></TR>
 * <TR><TD>111110</TD><TD>ME De-personalization Short Message</TD></TR>
 * <TR><TD>111111</TD><TD>(U)SIM Data download</TD></TR>
 * </TABLE>
 * <BR>
 * <BR>A short message type 0 indicates that the ME must acknowledge
 * receipt of the short message but shall discard its contents.
 * This means that 
 * <BR>
 * <BR> - the MS shall be able to receive the type 0 short message
 * irrespective of whether there is memory available in the (U)SIM
 * or ME or not,
 * <BR>
 * <BR> - the MS shall not indicate the receipt of the type 0 short
 * message to the user,
 * <BR>
 * <BR> - the short message shall neither be stored in the (U)SIM nor ME.
 * <BR>
 * <BR>The Replace Short Message feature is optional for the ME and the
 * (U)SIM but if implemented it shall be performed as described here.
 * <BR>
 * <BR>For MT short messages, on receipt of a short message from the SC,
 * the MS shall check to see if the associated Protocol. Identifier contains
 * a Replace Short Message Type code.
 * <BR>
 * <BR>If such a code is present, then the MS shall check the originating
 * address and replace any existing stored message having the same Protocol
 * Identifier code and originating address with the new short message and
 * other parameter values. If there is no message to be replaced, the MS
 * shall store the message in the normal way. The MS may also check the SC
 * address as well as the Originating Address. However, in a network which
 * has multiple SCs, it is possible for a Replace Message type for a SM to
 * be sent via different SCs and so it is recommended that the SC address
 * should not be checked by the MS unless the application specifically
 * requires such a check.
 * <BR>
 * <BR>If a Replace Short Message Type code is not present then the MS
 * shall store the message in the normal way.
 * <BR>
 * <BR>In MO short messages the SC reacts similarly but only the address
 * of the originating MS or any other source is checked.
 * <BR>
 * <BR>A Return Call Message indicates to the MS to inform the user that
 * a call (e.g. a telephone call) can be established to the address
 * specified within the TP-OA. The RP-OA contains the address of the SC
 * as usual. The message content (if present) gives displayable information
 * (e.g. the number of waiting voice messages). The message is handled in
 * the same way as all other messages of the Replace Short Message Types.
 * <BR>
 * <BR>The ME De-personalization Short Message is a ME-specific message which
 * instructs the ME to de-personalities the ME (see 3GPP TS 22.022 [25]).
 * The TP-DCS shall be set to Uncompressed, Default Alphabet, and Message
 * Class 1 (ME-specific), which corresponds to a bit coding of 00010001.
 * The TP-UD field contains de-personalization information coded according
 * to 3GPP TS 22.022 [25]. This information shall not be displayed by an ME
 * which supports the scheme. The acknowledgement to this message is a
 * SMS-DELIVER-REPORT for RP-ACK in which the TP-User-Data shall be coded
 * according to 3GPP TS 22.022 [25].
 * <BR>
 * <BR>(U)SIM Data download is a facility whereby the ME must pass the short
 * message in its entirety including all SMS elements contained in the SMS
 * deliver to the (U)SIM using the mechanism described in GSM TS 51.011 [16]
 * and 3GPP TS 31.102 [30]. The DCS shall be set to message class 2. The
 * entire user data field is available for (U)SIM Data download. If the DCS
 * is not set to message class 2 then the message shall be handled in the
 * normal way by the ME. However it has to be noted that MEs based on releases
 * of this specification earlier than REL-5 may allow only 8 bit message
 * class 2 with bit coding 11110110 or 00010110 for (U)SIM Data download.
 * <BR>
 * <BR>ME Data download is a facility whereby the ME shall process the short
 * message in its entirety including all SMS elements contained in the SMS
 * deliver to the ME. The DCS should normally be set to message class 1. If
 * the DCS is set to message class 1 and no application in the ME exists,
 * which is able to process the short message, the ME may discard the short
 * message. The entire user data field is available for ME data download.
 * The TPDU parameters required for the SMS-DELIVER should be passed
 * transparently by all involved SCs, so no TPDU parameter in the entire
 * short message is modified, other than the changes required to convert an
 * SMS-SUBMIT into an SMS-DELIVER.
 * <BR>
 * <BR>ANSI-136 R-DATA is a facility whereby the ME must pass the short
 * message in its entirety, including all elements contained in the SMS
 * DELIVER, to the (U)SIM using the mechanism described in GSM TS 11.14
 * [16] and 3GPP TS 31.102 [30]. The DCS shall be set to message class 2.
 * If the DCS is not set to message class 2 then the message shall be handled
 * in the normal way by the ME. However it has to be noted that MEs based on
 * releases of this specification earlier than REL-5 may allow only 8 bit
 * message class 2 with bit coding 11110110 or 00010110 for ANSI-136 RDATA.
 *
 *<BR><BR><BR><A HREF="http://www.dreamfabric.com/sms/pid.html">
 *                     http://www.dreamfabric.com/sms/pid.html</A>
 *
 * @author Stein Gunnar Bakkeby
 */
public class PID extends IntValue {

  /* Static field values */
  /* Group: PID Groups.  */
  /**
   * Telematic Interworking or SME-to-SME protocol.
   * <BR>
   * <BR>For Telematic Interworking devices see TI_ field values.
   */
  public static final int GROUP_TI          = 0;
  /**
   * Message Type Group.
   * <BR>
   * <BR>For Message Type see MT_ field values.
   */
  public static final int GROUP_MT          = 1;
  /** Reserved. */
  public static final int GROUP_RESERVED    = 2;
  /** SC Specific use. */
  public static final int GROUP_SC_SPECIFIC = 3;
  
  /* TI: Telematic Interworking */
  /** 
   * Implicit - device type is specific to this SC, or can be concluded on
   * the basis of the address.
   */
  public static final int TI_IMPLICIT                                  =  0;
  /** Telex (or teletex reduced to telex format). */
  public static final int TI_TELEX                                     =  1;
  /** Group 3 telefax. */
  public static final int TI_TELEFAX_GROUP_3                           =  2;
  /** Group 4 telefax. */
  public static final int TI_TELEFAX_GROUP_4                           =  3;
  /** Voice telephone (i.e. conversion to speech). */
  public static final int TI_VOICE_TELEPHONE                           =  4;
  /** ERMES (European Radio Messaging System). */
  public static final int TI_ERMES                                     =  5;
  /** National Paging System (known to the SC). */
  public static final int TI_NATIONAL_PAGING_SYSTEM                    =  6;
  /** Videotex (T.100/T.101). */
  public static final int TI_VIDEOTEX                                  =  7;
  /** Teletex, carrier unspecified. */
  public static final int TI_TELETEX_CARRIER_UNSPECIFIED               =  8;
  /** Teletex, in PSPDN. */
  public static final int TI_TELETEX_IN_PSPDN                          =  9;
  /** Teletex, in CSPDN. */
  public static final int TI_TELETEX_IN_CSPDN                          = 10;
  /** Teletex, in analog PSTN. */
  public static final int TI_TELETEX_IN_ANALOG_PSTN                    = 11;
  /** Teletex, in digital ISDN. */
  public static final int TI_TELETEX_IN_DIGITAL_ISDN                   = 12;
  /** UCI (Universal Computer Interface, ETSI DE/PS 3 01-3). */
  public static final int TI_UNIVERSAL_COMPUTER_INTERFACE              = 13;
  /** Reserved. */
  public static final int TI_RESERVED_01110                            = 14;
  /** Reserved. */
  public static final int TI_RESERVED_01111                            = 15;
  /** A message handling facility (known to the SC). */
  public static final int TI_MESSAGE_HANDLING_FACILITY                 = 16;
  /** Any public X.400-based message handling system. */
  public static final int TI_PUBLIC_X400_BASED_MESSAGE_HANDLING_SYSTEM = 17;
  /** Internet Electronic Mail. */
  public static final int TI_INTERNET_ELECTRONIC_MAIL                  = 18;
  /** Reserved. */
  public static final int TI_RESERVED_10011                            = 19;
  /** Reserved. */
  public static final int TI_RESERVED_10100                            = 20;
  /** Reserved. */
  public static final int TI_RESERVED_10101                            = 21;
  /** Reserved. */
  public static final int TI_RESERVED_10110                            = 22;
  /** Reserved. */
  public static final int TI_RESERVED_10111                            = 23;  
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC.
   */
  public static final int TI_SC_SPECIFIC_11000                         = 24;
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC.
   */
  public static final int TI_SC_SPECIFIC_11001                         = 25;
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC. 
   */
  public static final int TI_SC_SPECIFIC_11010                         = 26;
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC.
   */
  public static final int TI_SC_SPECIFIC_11011                         = 27;
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC.
   */
  public static final int TI_SC_SPECIFIC_11100                         = 28;
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC.
   */
  public static final int TI_SC_SPECIFIC_11101                         = 29;
  /**
   * Values specific to each SC, usage based on mutual agreement between
   * the SME and the SC.
   */
  public static final int TI_SC_SPECIFIC_11110                         = 30;
  /**
   * A GSM/UMTS mobile station. The SC converts the SM from the received
   * TP-Data-Coding-Scheme to any data coding scheme supported by that MS
   * (e.g. the default).
   */
  public static final int TI_GSM_MOBILE_STATION                        = 31;

  /*
   * MT: Message Type.
   */
  /**
   * A short message type 0 indicates that the ME must acknowledge
   * receipt of the short message but may discard its contents.
   */
  public static final int MT_SHORT_MESSAGE_TYPE_0 = 0;
  /**
   * Replace Short Message 1. The Replace Short Message feature is optional
   * for the ME and the SIM but if implemented it shall be performed as
   * described here.
   *
   * For MT short messages, on receipt of a short message from from
   * the SC, the MS shall check to see if the associated Protocol
   * Identifier contains a Replace Short Message Type code.
   *
   * If such a code is present, the the MS will check the originating
   * address and replace any existing stored message having the same
   * Protocol Identifier code and originating address with the new
   * short message and other parameter values. If there is no message
   * to be replaced, the MS shall store the message in the normal
   * way. The MS may also check the SC address as well as the
   * Originating Address. However, in a network which has multiple
   * SCs, it is possible for a Replace Message type for a SM to be
   * sent via different SCs and so it is recommended that the SC
   * address should not be checked by the MS unless the application
   * specifically requires such a check.
   *
   * If a Replace Short Message Type code is not present then the MS
   * will will store the message in the normal way.
   *
   * In MO short messages the SC reacts similarly but only the
   * address of the originating MS or any other source is checked.
   */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_1 = 1;
  /** Replace Short Message Type 2. */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_2 = 2;
  /** Replace Short Message Type 3. */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_3 = 3;
  /** Replace Short Message Type 4. */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_4 = 4;
  /** Replace Short Message Type 5. */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_5 = 5;
  /** Replace Short Message Type 6. */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_6 = 6;
  /** Replace Short Message Type 7. */
  public static final int MT_REPLACE_SHORT_MESSAGE_TYPE_7 = 7;
  /** Enhanced Message Service (Obsolete). */
  public static final int MT_ENHANCED_MESSAGE_SERVICE = 30;
  /**
   * A Return Call Message indicates to the MS to inform the user
   * that a call (e.g. a telephone call) can be established to the
   * address specified within the TP-OA. The RP-OA contains the
   * address of the SC as usual. The message content (if present)
   * gives displayable information (e.g. the number of waiting voice
   * messages). The message is handled in the same way as all other
   * messages of the Replace Short Message Types.
   */
  public static final int MT_RETURN_CALL_MESSAGE = 31;
  /** ANSI-136 R-DATA. */
  public static final int MT_ANSI_136_R_DATA = 60;
  /**
   * ME Data download is facility whereby the ME shall process the
   * short message in its entirety including all SMS elements
   * contained in the SMS deliver to the ME. The DCS shall be set to
   * message class 1. The entire user data field is available for
   * ME data download.
   */
  public static final int MT_DATA_DOWNLOAD = 61;
  /**
   * The ME De-personalization Short Message is an ME-specific
   * message which instructs the ME to de-personalities the ME
   * (see GSM 2.22). The TP-DCS shall be set to Uncompressed, Default
   * Alphabet, and Message Class 1 (Me-specific), which corresponds
   * to a bit coding of 00010001. The TP-UD field contains
   * de-personalization information coded according to GSM 02.22.
   * This information shall not be displayed by an ME which supports
   * the scheme. The acknowledgement to this message is a
   * SMS-DELIVER-REPORT for RP-ACK in which the TP-User-Data shall be
   * coded according to GSM 02.22.
   */
  public static final int MT_ME_DEPERSONALIZATION_SHORT_MESSAGE = 62;
  /**
   * (U)SIM Data download is a facility whereby the ME must pass the
   * short message in its entirety including all SMS elements
   * contained in the SMS deliver to the SIM using the mechanism
   * described in GSM 11.11. The DCS shall be set to 8 bit message
   * class 2 (either bit coding 11110110 or 00010110). The entire
   * user data field is available for SIM Data download.
   */
  public static final int MT_SIM_DATA_DOWNLOAD = 63;
  /* End static field values */
  
  /** Inherited constructor from IntValue. */
  public PID() {
    super(0);
  }
  
  /**
   * Inherited constructor from IntValue.
   * @param value The value of this object
   */
  public PID(final int value) {
    super(value);
  }
  
  /**
   * Inherited constructor from IntValue.
   * @param hex The value of this object in hex
   */
  public PID(final String hex) {
    super(hex);
  }
  
  /**
   * Returns an integer representing the PID group.
   * <BR>
   * Note: See GROUP field values.
   * 
   * @return The group defined by the argument.
   */
  public int getGroup() {
    return value & 0xC0; // B7|B6
  }
  
  /**
   * This will set the PID group.
   * 
   * @param group See static field values
   * @throws IllegalArgumentException If not a recognised value
   */
  public void setGroup(final int group) throws IllegalArgumentException {
    switch (group) {
    case GROUP_TI:
    case GROUP_MT:
    case GROUP_RESERVED:
    case GROUP_SC_SPECIFIC:
      value = (group << 6);
      break;
      
    default:
      throw new IllegalArgumentException("Use PID field values!");
    }
  }
  
  /**
   * This will set the PID value.
   * <BR>
   * <BR>Note that the user should first set the PID group. If the
   * PID group is 0, then the interworking (or SME-to-SME protocol)
   * may be set. Field values are used for PID groups 0 and 1. For 
   * PID groups 3 and 4 there are no defined values as group 3 is
   * reserved and group 4 is service center specific. Telematic
   * interworking (TI) field values are used for group 0, while
   * message type (MT) field values are used for gorup 1.
   *
   * @param pid See field values
   */
  public void setValue(final int pid) {
    switch ((value & 0xC0) >> 6) { // B7|B6
    case GROUP_TI:
      value = (value & 0xE0) | pid; // B7|B6|B5
      break;
      
    case GROUP_MT:
    case GROUP_RESERVED:
    case GROUP_SC_SPECIFIC:
      value = (value & 0xC0) | pid; // B7|B6
      break;
    
    default: // TODO reconsider exception
      throw new IllegalStateException("Illegal Group");
    }
  }
  
  /**
   * This will return the PID value.
   * 
   * @return See static field values
   * @see #getGroup()
   */
  public int getPIDValue() {
    switch (value & 0xC0) { // B7|B6
    case GROUP_TI:
      return value & 0x1F; // B4|B3|B2|B1|B0
      
    case GROUP_MT:
    case GROUP_RESERVED:
    case GROUP_SC_SPECIFIC:
      return value & 0x3F; // B5|B4|B3|B2|B1|B0
    
    default:
      /* Should never happen. */
      return 0;
    }
  }
  
  /**
   * Returns true if interworking is used, otherwise no interworking,
   * but SME-to-SME protocol.<BR>
   * Note: Only used in group 0.
   *
   * @return A boolean value telling if interworking is used
   */
  public boolean isInterworkingUsed() {
    return ((value & 0xC0) == 0) && ((value & B5) != 0); // B7|B6
  }
  
  /**
   * This will set telematic interworking to be used.
   * <BR>
   * Note that the telematic interworking can only be
   * used when the PID group is 0. If this is set to
   * false then it indicates that SME-to-SME protocol
   * is to be used. If set, then bits 4 to 0 are all
   * set to 0's.
   * 
   * @param bool True if interworking is to be used, false otherwise
   * @throws IllegalArgumentException If PID group is not 0
   */
  public void setInterworkingUsed(final boolean bool)
      throws IllegalArgumentException {
    if ((value & 0xC0) != 0) throw new IllegalArgumentException(
        "Error in PID.setInterworkingUsed(boolean): PID group not 0");
    value &= 0xC0; // B7|B6 - remove everything except group
    if (bool) value |= B5;
  }
}